package com.tiantian.quanminxiu.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tiantian.quanminxiu.R;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * Created by admin on 2016/1/14.
 */
public class GiftRecordAdapter extends RecyclerView.Adapter<GiftRecordAdapter.MyViewHolder>
{

    private Activity activity;
    private JSONArray list;
    public GiftRecordAdapter(Activity activity, JSONArray list){
        this.activity = activity;
        this.list = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                activity).inflate(R.layout.dialog_giftrecord_item, parent,
                false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position)
    {
        JSONObject gift = list.optJSONObject(position);
        holder.txtGiftTime.setText(gift.optString("CreateDate"));
        holder.txtUserName.setText(gift.optJSONObject("RoomUserInfo").optString("NickName"));
        JSONObject info = gift.optJSONObject("GiftInfo");
        holder.txtGiftInfo.setText(info.optString("Name")+"#"+gift.optString("GiftNum"));
    }

    @Override
    public int getItemCount()
    {
        return list.length();
    }

    class MyViewHolder extends RecyclerView.ViewHolder
    {
        TextView txtGiftTime,txtUserName,txtGiftInfo;

        public MyViewHolder(View view)
        {
            super(view);
            txtGiftTime = (TextView) view.findViewById(R.id.txtGiftTime);
            txtUserName = (TextView) view.findViewById(R.id.txtUserName);
            txtGiftInfo = (TextView) view.findViewById(R.id.txtGiftInfo);
        }
    }

}
